package com.scau.os.controller;


import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

public class ConsoleController {

    @FXML
    ScrollPane scrollPane;
    @FXML
    VBox vBox;
    @FXML
    VBox history;
    @FXML
    TextField inputField;
    @FXML
    Label tipLabel;

    public void initialize(){
        vBox.prefWidthProperty().bind(scrollPane.widthProperty().multiply(0.98));//绑定输入框和窗口大小关系
        //回车事件
        inputField.setOnKeyPressed( event -> {
            if( event.getCode() == KeyCode.ENTER ) {
                showInfoOnConsole(inputField.getText(),Color.WHITE);
                //showInfoOnConsole(doSomething());
                inputField.clear();
            }
        } );
    }

    //打印信息到“控制台”上
    private void showInfoOnConsole(String s,Color color){
        Label label=new Label(s);
        label.setTextFill(color);
        label.setFont(new Font("Arial",15));
        history.getChildren().add(label);
    }
}
